<%@ page import="com.liliya.service.impl.EmpServiceImpl" %>
<%@ page import="com.liliya.service.EmpService" %>
<%@ page import="com.liliya.pojo.Emp" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/1/5
  Time: 11:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试emp</title>
</head>
<%
    //当前是第几页
    int num = 1;
    String pageNum = request.getParameter("pageNum");
    if (pageNum!=null){
        num = Integer.parseInt(pageNum);
    }
    //每次查询5条数据
    int step = 2;
    int start = (num-1) * step +1;
    int end = num*step;
    EmpService empService = new EmpServiceImpl();
    List<Emp> emps = empService.findEmps(start, end);
    int total = empService.findPageCount(step);
    //判断是否跑出去了
    int pre = num-1 <=0 ? 1:num-1;
    int next = num+1>=total ? total:num+1;
%>
<body>
<table border="1">
    <tr>
        <th>用户编号</th>
        <th>用户名</th>
    </tr>

    <%
        for (Emp emp : emps) {
    %>
        <tr>
            <td><%=emp.getEmpno()%></td>
            <td><%=emp.getEname()%></td>
        </tr>
    <%
        }
    %>


</table>
<a href="${pageContext.request.contextPath}/emplist.jsp?pageNum=1">首页</a>
<a href="${pageContext.request.contextPath}/emplist.jsp?pageNum=<%=pre%>">上一页</a>
<a href="${pageContext.request.contextPath}/emplist.jsp?pageNum=<%=next%>">下一页</a>
<a href="${pageContext.request.contextPath}/emplist.jsp?pageNum=<%=total%>">末页</a>
</body>
</html>
